
/**
 * Created on Oct 27, 2004
 *
 * 2004-11-24 Nathan Anderson [nanderson@melinate.com]
 * - modified test to compile after adding case sensitive
 *   logic.  Test will not work for case sensitive DB's
 *   but at least it continues to work for other DB's
 */
package com.codegenerator.testcases;

import com.codegenerator.common.ApplicationProperties;
import com.codegenerator.common.ListHashtable;
import com.codegenerator.common.ThreadContext;
import com.codegenerator.db.ForeignKey;
import com.codegenerator.db.ForeignKeys;
import com.codegenerator.db.SqlTable;

import junit.framework.TestCase;

/**
 * @author Richard Che So
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestSqlTableForeignKeys extends TestCase {

	SqlTable sqlTable = null;
	
	public static void main(String[] args) {
	}

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		sqlTable = new SqlTable("personal_finance", "", true,"");
	}

	/*
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
		sqlTable = null;
		ThreadContext.getCurrentContext().terminate(true);
	}


	public void testSqlTableForeignKeys() {
		assertEquals("personal_finance", sqlTable.getTable());
		assertEquals("",  sqlTable.getSchema());
		assertTrue(sqlTable.getAllColumns().size() == 6);
		assertTrue(sqlTable.getPrimaryKeys().size() == 3);
		assertTrue(sqlTable.getPrimaryKey(0).isKey());
		assertTrue(sqlTable.getImportedKeys().getAssociatedTables().size() == 2);
		ListHashtable tables = ApplicationProperties.getSqlTables();
		assertTrue(tables.containsKey("personal_finance"));
		assertTrue(tables.containsKey("person_info"));
		assertTrue(tables.containsKey("bank_info"));
		assertTrue(tables.containsKey("financial_institutions"));
		ForeignKeys fkeys = sqlTable.getImportedKeys();
		ForeignKey  fkey = fkeys.getAssociatedTable("person_info");
		assertTrue(fkey.getColumns().size() == 2);
		System.out.println("Personal_finance relation with Person_info = "+fkey.getRelationShip());
		
		SqlTable bankInfo = (SqlTable) tables.get("bank_info");
		ForeignKeys ikeys = bankInfo.getExportedKeys();
		ForeignKey  nfkey = ikeys.getAssociatedTable("personal_finance");
		System.out.println("Bank_info relation with personal_finance = "+nfkey.getRelationShip());
	}

}
